package PTA_5;

import java.util.Scanner;

public class t5 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String set = scan.next();
        String key = "[A-Z]"+"[a-z]{3}"+"\\d{3}";
        if(set.matches(key)) {
            System.out.println(set + "合法");
        }else {
            System.out.println(set + "不合法");
        }
    }
}
